package com.cat.greedyAlgorithm;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/longest-subarray-of-1s-after-deleting-one-element/?envType=daily-question&envId=2025-08-24
 * @create 2025/8/24 08:52
 * @since JDK17
 */

public class Solution23 {
    public int longestSubarray(int[] nums) {
        int ans = 0, sum = 0, n = nums.length;
        for (int i = 0, j, last; i < n; i++) {
            if (nums[i] == 0) {
                continue;
            }
            j = i;
            while (i < n && nums[i] != 0) {
                i++;
            }
            last = i++;
            while (i < n && nums[i] != 0) {
                i++;
            }
            ans = Math.max(ans, i - j - 1);
            i = last;
        }
        return ans;
    }
}
